package com.aliyun.messagemgt.web.controller;

import com.aliyun.messagemgt.application.service.SmsSignService;
import com.aliyun.messagemgt.dto.vo.SmsSignVO;
import com.aliyun.messagemgt.fouraplugin.FouraService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: li.wy
 * @create: 2020-10-29
 **/
@RestController
@RequestMapping("/smsSign")
public class SmsSignController {
    @Autowired
    private SmsSignService smsSignService;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private FouraService fouraService;

    @GetMapping
    public Object getSmsSigns(@RequestParam(value = "templateId", required = false) Integer templateId) {
        return smsSignService.getSmsSigns(templateId);
    }

    @PostMapping("/findAll")
    @ApiOperation("分页查询短信签名表")
    public Object findAll() {
        return smsSignService.findAll();
    }

    @PostMapping("/insert")
    @ApiOperation("新增短信签名表")
    public Object insert(@RequestBody SmsSignVO smsSignVo) {
        String accountInfo = fouraService.getSsoUser(request);
        smsSignVo.setUserCreate(accountInfo);
        smsSignVo.setUserUpdate(accountInfo);
        return smsSignService.insert(smsSignVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改短信签名表")
    public Object update(@RequestBody SmsSignVO smsSignVo) {
        String accountInfo = fouraService.getSsoUser(request);
        smsSignVo.setUserUpdate(accountInfo);
        return smsSignService.update(smsSignVo);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("通过ID删除单个短信签名表")
    public Object deleteById(@ApiParam("ID") @PathVariable("id") Integer id) {
        String accountInfo = fouraService.getSsoUser(request);
        return smsSignService.deleteById(id, accountInfo);
    }

}
